package com.guaika.reggie.common;

import lombok.Data;
import java.util.HashMap;
import java.util.Map;

/**
 * 通用返回结果
 * @author GuaiKa
 */
@Data
public class ResultMessage<T> {
    /**
     * 编码：1成功，0和其它数字为失败
     */
    private Integer code;
    /**
     *错误信息
     */
    private String msg;
    /**
     *数据
     */
    private T data;
    /**
     *动态数据
     */
    private Map map = new HashMap();

    public static <T> ResultMessage<T> success(T object) {
        ResultMessage<T> r = new ResultMessage<T>();
        r.data = object;
        r.code = 1;
        return r;
    }

    public static <T> ResultMessage<T> error(String msg) {
        ResultMessage r = new ResultMessage();
        r.msg = msg;
        r.code = 0;
        return r;
    }

    public ResultMessage<T> add(String key, Object value) {
        this.map.put(key, value);
        return this;
    }

}
